package com.seata.demo.controller;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.seata.demo.service.BusinessService;
import com.seata.demo.util.res.Resp;
import lombok.extern.slf4j.Slf4j;
/**
* @comments
* @author  zg
* @date 2021年2月9日
*/
@Slf4j
@Validated
@RestController
@RequestMapping("/biz/")
public class BusinessController {
    
    @Autowired
    private BusinessService businessService;
    
    @RequestMapping("/purchase")
    public Resp<?> purchase(
            @NotBlank(message = "userId不能为空")String userId, 
            @NotBlank(message = "商品编码不能为空")String commodityCode, 
            @NotNull(message = "商品数量不能为空") @Min(value = 1, message = "商品数量最小为1") Integer commodityCount) {
        
        log.info("购买商品userId={}, commodityCode={}, commodityCount={}", userId, commodityCode, commodityCount);
        return businessService.purchase(userId, commodityCode, commodityCount);
    }
    
}
